package migrations

import (
	"database/sql"
	"time"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/migrate"

	"gorm.io/gorm"
)

// http://sql2struct.atotoa.com/
func init() {

	type Vehicle struct {
		models.BaseModel

		BrandId        uint64    `gorm:"column:brand_id;comment:品牌id;" db:"brand_id" json:"brand_id" form:"brand_id"`                              //车辆品牌
		ModelId        uint64    `gorm:"column:model_id;comment:型号id;" db:"model_id" json:"model_id" form:"model_id"`                              //车辆型号
		Year           time.Time `gorm:"column:year;type:timestamp;comment:车辆出厂日期;" db:"year" json:"year" form:"year"`                             //车辆出厂日期
		Color          string    `gorm:"type:varchar(255);comment:颜色;" db:"color" json:"color" form:"color"`                                       //颜色
		LicensePlate   string    `gorm:"type:varchar(255);comment:车牌号;index;" db:"license_plate" json:"license_plate" form:"license_plate"`        //车牌号
		Mileage        float64   `gorm:"column:mileage;comment:行驶公里数;" db:"mileage" json:"mileage" form:"mileage"`                                 //行驶公里数
		FuelId         uint64    `gorm:"column:fuel_id;comment:燃油类型;" db:"fuel_id" json:"fuel_id" form:"fuel_id"`                                  //燃油类型
		TransmissionId uint64    `gorm:"column:transmission_id;comment:变速器类型;" db:"transmission_id" json:"transmission_id" form:"transmission_id"` //变速器类型
		EngineSize     float64   `gorm:"column:engine_size;comment:发动机排量;" db:"engine_size" json:"engine_size" form:"engine_size"`                 //发动机排量
		Seats          uint8     `gorm:"column:seats;comment:座位数(不算司机);" db:"seats" json:"seats" form:"seats"`                                     //座位数
		UserId         uint64    `gorm:"column:user_id" db:"user_id" json:"user_id" form:"user_id"`

		models.CommonTimestampsField
	}
	up := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.AutoMigrate(&Vehicle{})
	}

	down := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.DropTable(&Vehicle{})
	}

	migrate.Add("2023_07_18_151435_add_vehicles_table", up, down)
}
